<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('销售订单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>订单号：</label>
                                <input type="text" name="orderCode" id="orderCode"/>
                            </li>
                            <li>
                                <label>客户名称：</label>
                                <input type="text" name="customerName"/>
                            </li>
                            <li>
                                <label >业务责任人：</label>
                                <input type="text" name="businessManager"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="order:saleorder:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary multiple " onclick="$.operate.audit()" shiro:hasPermission="order:saleorder:audit">
                    <i class="fa fa-ticket"></i> 审核
                </a>
                <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="order:purchorder:edit">-->
                <!--<i class="fa fa-edit"></i> 修改-->
                <!--</a>-->
                <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="order:purchorder:remove">-->
                <!--<i class="fa fa-remove"></i> 删除-->
                <!--</a>-->
                <!--<a class="btn btn-danger multiple" onclick="$.operate.removeAll()" shiro:hasPermission="order:saleorder:remove">-->
                    <!--<i class="fa fa-ticket"></i> 生产完成-->
                <!--</a>-->
                <!--<a class="btn btn-success multiple" onclick="$.operate.add()" shiro:hasPermission="order:saleorder:add">-->
                    <!--<i class="fa fa-comment"></i> 发货-->
                <!--</a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="order:saleorder:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <!--<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="order:saleorder:add">-->
                    <!--<i class="fa fa-print"></i> 打印-->
                <!--</a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>

        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var orderStatusDatas = [[${@dict.getType('order_status')}]];
        var productionStatusDatas = [[${@dict.getType('production_status')}]];
        var deliveryStatusDatas = [[${@dict.getType('delivery_status')}]];
        var receiveStatusDatas = [[${@dict.getType('receive_money_status')}]];
        var editFlag = [[${@permission.hasPermi('order:saleorder:edit')}]];
        var removeFlag = [[${@permission.hasPermi('order:saleorder:remove')}]];
        var prefix = ctx + "order/saleorder";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                auditUrl: prefix + "/audit",
                modalName: "销售订单",
                detailView: true,
                onExpandRow: function (index, row, $detail) {
                    initChildTable(index, row, $detail);
                },
                columns: [{
                    checkbox: true
                },
                    // {
                    //     title: '序号',
                    //     formatter: function (value, row, index) {
                    //         return index + 1;
                    //     },
                    //     rowspan: 1,
                    //     align: 'center',
                    //     width: '50px'
                    // },
                    {
                        field: 'id',
                        title: '客户id',
                        visible: false
                    },
                    {
                        field: 'orderCode',
                        title: '订单号'
                    },
                    {
                        field: 'providerName',
                        title: '供方'
                    },
                    {
                        field: 'customerName',
                        title: '客户名称'
                    },
                    {
                        field: 'businessManager',
                        title: '业务责任人'
                    },
                    {
                        field: 'orderDate',
                        title: '订单日期'
                    },
                    {
                        field: 'amounts',
                        title: '销售金额'
                    },
                    {
                        field: 'receiveAmount',
                        title: '收款金额'
                    },
                    {
                        field: 'orderStatus',
                        title: '订单状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(orderStatusDatas, value);
                        }
                    },
                    {
                        field: 'produceStatus',
                        title: '生产状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(productionStatusDatas, value);
                        }
                    },
                    {
                        field: 'deliveryStatus',
                        title: '发货状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(deliveryStatusDatas, value);
                        }
                    },
                    {
                        field: 'receiveStatus',
                        title: '收款状态',
                        formatter: function (value, row, index) {
                            return $.table.selectDictLabel(receiveStatusDatas, value);
                        }
                    },
                    {
                        field: 'remark',
                        title: '备注'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var actions = [];
                            if (row.orderStatus == 0) {
                                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                            }else if(row.orderStatus == 1){
                                actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="saleOutOrder(\'' + row.id + '\')"><i class="fa fa-inbox"></i>一键出库</a> ');
                            }
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
            });

        initChildTable = function(index,rows,$detail){
                var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
                $(childTable).bootstrapTable({
                    url: prefix + "/item/list",
                    method: 'post',
                    sidePagination: "server",
                    contentType: "application/x-www-form-urlencoded",
                    queryParams: {
                        saleOrderId: rows.id
                    },
                    columns: [{
                        checkbox: true
                    },
                    {
                        field: 'goodsCode',
                        title: '产品编码'
                    },
                    {
                        field: 'goodsName',
                        title: '产品品名'
                    },
                    {
                        field: 'goodsUnit',
                        title: '单位'
                    },
                    {
                        field: 'goodsFormat',
                        title: '规格'
                    },
                    {
                        field: 'saleNumber',
                        title: '数量'
                    },
                    {
                        field: 'price',
                        title: '单价'
                    },
                    {
                        field: 'amount',
                        title: '总价'
                    },
                    {
                        field: 'remark',
                        title: '要求'
                    },
                        {
                            title: '操作',
                            align: 'center',
                            formatter: function (value, row, index) {
                                var actions = [];
                                if(rows.orderStatus == 1) {
                                    actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="saleProduct(\'' + row.id + '\')"><i class="fa fa-inbox"></i>一键生产</a> ');
                                }
                                return actions.join('');
                            }
                        }
                    ]
                });
            }


        function saleProduct(id) {
            var preViewUrl=ctx+'order/productorder/saleProduct?id='+id;
            $.modal.openTab("销售一键生产", preViewUrl);
        }

        function saleOutOrder(id) {
            var preViewUrl=ctx+'store/outorder/saleOutOrder?id='+id;
            $.modal.openTab("销售一键出库", preViewUrl);
        }
    </script>
</body>
</html>